package com.ruoyi.system.service.vantservice.orderservice.impl;

import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderComment;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.OrderCommentPicture;
import com.ruoyi.system.domain.zhuangxiumain.vo.OrderCommentVo;
import com.ruoyi.system.mapper.vant.order.ApiOrderCommentMapper;
import com.ruoyi.system.mapper.vant.order.ApiOrderCommentPictureMapper;
import com.ruoyi.system.service.vantservice.orderservice.ApiOrderCommentService;
import com.ruoyi.system.utils.IdentifiedGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by 惠普 on 2020/12/28 17:32
 */
@Service("apiOrderCommentService")
public class ApiOrderCommentServiceImpl implements ApiOrderCommentService {
    @Resource
    private ApiOrderCommentMapper apiOrderCommentMapper;
    @Resource
    private ApiOrderCommentPictureMapper apiOrderCommentPictureMapper;

    /**
     * 添加评论信息
     * @param orderComment
     * @return
     */
    @Override
    public int addOrderComment(OrderComment orderComment) {
        int row = 0;
        int u = IdentifiedGenerator.Num();
        orderComment.setOrderCommentPicture(u);
        row = apiOrderCommentMapper.addOrderComment(orderComment);
        if(row == 1){
            OrderCommentPicture orderCommentPicture = new OrderCommentPicture();
            orderCommentPicture.setOrderCommentPictureUuid(u);
            if(orderComment.getImg0()!=null){
                orderCommentPicture.setOrderCommentPictureUrl(orderComment.getImg0());
                apiOrderCommentPictureMapper.addOrderCommentPicture(orderCommentPicture);
            }
            if(orderComment.getImg1()!=null){
                orderCommentPicture.setOrderCommentPictureUrl(orderComment.getImg1());
                apiOrderCommentPictureMapper.addOrderCommentPicture(orderCommentPicture);
            }
            if(orderComment.getImg2()!=null){
                orderCommentPicture.setOrderCommentPictureUrl(orderComment.getImg2());
                apiOrderCommentPictureMapper.addOrderCommentPicture(orderCommentPicture);
            }
            if(orderComment.getImg3()!=null){
                orderCommentPicture.setOrderCommentPictureUrl(orderComment.getImg3());
                apiOrderCommentPictureMapper.addOrderCommentPicture(orderCommentPicture);
            }
        }
        return row;
    }

    /**
     * 用户的全部评论
     * @param orderCommentVo
     * @return
     */
    @Override
    public List<OrderCommentVo> selectOrderCommentVo(OrderCommentVo orderCommentVo) {
        List<OrderCommentVo> list = apiOrderCommentMapper.selectOrderCommentVo(orderCommentVo);
        for (OrderCommentVo orderCommentVo1 : list){
            orderCommentVo1.setOrderCommentPictureList(apiOrderCommentPictureMapper.selectOrderCommentPictureByUuid(orderCommentVo1.getOrderCommentPicture()));
        }
        return list;
    }

}
